// miniprogram/pages/my/my.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    order_list: [{
        name: '全部订单',
        img: '../../images/or1.png'
      },
      {
        name: '待付款',
        img: '../../images/or2.png'
      },
      {
        name: '待发货',
        img: '../../images/or3.png'
      },
      {
        name: '待收货',
        img: '../../images/or4.png'
      },
      {
        name: '退款/售后',
        img: '../../images/or5.png'
      },
    ],
    user_credit: [{
        txt: '积分',
        num: 0
      },
      {
        txt: '优惠券',
        num: 1
      },
      {
        txt: '礼品卡',
        num: 4
      },
      {
        txt: '赠品',
        num: 1
      }
    ],
    site_list: [{
        img: '../../images/my2.png',
        name: '收货地址'
      },
      {
        img: '../../images/my3.png',
        name: '个人资料'
      },
      {
        img: '../../images/my4.png',
        name: '我的收藏'
      }, {
        img: '../../images/my6.png',
        name: '超级管理员'
      }
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.getMyUserInfo();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },
  getMyUserInfo() {
    let _this = this;
    let db = wx.cloud.database();
    wx.cloud.callFunction({
      name: 'login',
      success: res => {
        let openid = res.result.openid;
        db.collection('tb_user_list').where({
          _openid: openid
        }).get({
          success: resp => {
            console.log(resp)
            _this.setData({
              uinfo: resp.data[0]
            })
          },
          fail: err => {
            console.log(err)
          }
        })
      },
      fail: err => {
        console.log(err)
      }
    })
  },
  getPhoneNumber(e) {
    console.log(e);
    let uinfo = this.data.uinfo;
    if (e.detail.errMsg == 'getPhoneNumber:fail user deny') {
      return wx.showToast({
        title: '您拒绝了绑定',
      })
    }
    
  },
  goAllOrder() {
    wx.navigateTo({
      url: '../applications/order/order',
    })
  },
  goOtherViews(e) {
    let idx = e.currentTarget.dataset.idx;
    if (idx == 0) {
      wx.navigateTo({
        url: '../applications/address/address',
      })
    } else if (idx == 1) {

    } else if (idx == 2) {
      wx.navigateTo({
        url: '../applications/collect/collect',
      })
    } else {
      wx.navigateTo({
        url: '../applications/admin/admin',
      })
    }
  },
  goOrderList(e) {
    let id = e.currentTarget.dataset.idx;
    console.log(id);
    wx.navigateTo({
      url: '../applications/order/order?id=' + id,
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})